package com.example.springdemo.Controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;

import com.example.springdemo.entity.Address;
import com.example.springdemo.entity.Goods;
import com.example.springdemo.service.IAddressService;
import com.example.springdemo.utils.PassToken;
import com.example.springdemo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * addressController
 * 
 * @author ruoyi
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/system/address")
public class AddressController
{
    @Autowired
    private IAddressService addressService;

    /**
     * 查询address列表
     */
    @PassToken
    @GetMapping("/list")
    public ResponseResult list(Address address)
    {
//        startPage();
//        List<Address> list = addressService.selectAddressList(address);
//        return getDataTable(list);
        return ResponseResult.createBySuccess(200,addressService.selectAddressList(address),"查询成功");
    }
    @PassToken
    @GetMapping("/frontlist")
    public ResponseResult list1(Address address) {
        System.out.println(address.getAddressid());
        return ResponseResult.createBySuccess(200,address,"获取成功");
    }

    /**
     * 导出address列表
     */
//    @Log(title = "address", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Address address)
//    {
//        List<Address> list = addressService.selectAddressList(address);
//        ExcelUtil<Address> util = new ExcelUtil<Address>(Address.class);
//        util.exportExcel(response, list, "address数据");
//    }

    /**
     * 获取address详细信息
     */
@PassToken
    @GetMapping(value = "/{addressid}")
    public ResponseResult getInfo(@PathVariable("addressid") Long addressid)
    {
        Address address = addressService.selectAddressByAddressid(addressid);
        return ResponseResult.createBySuccess(200,addressid,"查询成功");
    }

    /**
     * 新增address
     */
    @PassToken
    @PostMapping
    public ResponseResult add(@RequestBody Address address)
    {
        int i = addressService.insertAddress(address);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "添加成功");
        } else {
            return ResponseResult.createByFail(200, "添加失败");
        }
    }

    /**
     * 修改address
     */
@PassToken
    @PutMapping
    public ResponseResult edit(@RequestBody Address address)
    {
        int i = addressService.updateAddress(address);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "修改成功");
        } else {
            return ResponseResult.createByFail(200, "修改失败");
        }
    }

    /**
     * 删除address
     */
@PassToken
	@DeleteMapping("/{addressids}")
    public ResponseResult remove(@PathVariable Long[] addressids)
    {
        int i = addressService.deleteAddressByAddressids(addressids);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "删除成功");
        } else {
            return ResponseResult.createByFail(200, "删除失败");
        }
    }
}
